import { useRequest, type Options } from 'vue-request'
import http, { type RequestParams } from '@/services/http'
import type { AxiosRequestConfig } from 'axios'

export function useGet<R, P extends unknown[]>(
  url: string,
  options?: Options<R, P>,
  config?: AxiosRequestConfig,
) {
  return useRequest(
    (...params: P) => http.get<R>(url, params[0] as RequestParams, config),
    {
      ...options,
    },
  )
}
export function usePost<R, P extends unknown[]>(
  url: string,
  options?: Options<R, P>,
  config?: AxiosRequestConfig,
) {
  return useRequest((...params: P) => http.post<R>(url, params[0], config), {
    ...options,
  })
}
export function usePut<R, P extends unknown[]>(
  url: string,
  options?: Options<R, P>,
  config?: AxiosRequestConfig,
) {
  return useRequest((...params: P) => http.put<R>(url, params[0], config), {
    ...options,
  })
}
export function useDelete<R, P extends unknown[]>(
  url: string,
  options?: Options<R, P>,
  config?: AxiosRequestConfig,
) {
  return useRequest(
    (...params: P) => http.delete<R>(url, params[0] as RequestParams, config),
    {
      ...options,
    },
  )
}
